<script setup>
// 文章分类 模块
import { ref, onMounted } from 'vue'
import { artDelChannelService, artGetChannelsService } from '@/api/article'
import { Edit, Delete } from '@element-plus/icons-vue'
import ChannelEdit from './components/ChannelEdit.vue'
import { ElMessage } from 'element-plus'
import pageContainer from '@/components/PageContainer.vue'

const channelList = ref([])
const isLoading = ref(false)
const channelEdit = ref(null)
// 获取文章分类
const getChannelList = async () => {
  isLoading.value = true
  const res = await artGetChannelsService()
  channelList.value = res.data
  isLoading.value = false
}
onMounted(() => {
  getChannelList()
})
// eslint-disable-next-line no-unused-vars
const edit = (row, index) => {
  channelEdit.value.open(row)
  // console.log(row, index)
}
const del = async (row, index) => {
  await ElMessageBox.confirm('你确认要删除这条信息吗', '温馨提示', {
    type: 'warning',
    confirmButtonText: '确认',
    cancelButtonText: '取消'
  })
  await artDelChannelService(row.id)
  ElMessage.success({ message: '删除成功' })
  getChannelList()
  console.log(row, index)
}
</script>
<template>
  <page-container title="文章分类">
    <template #extra>
      <el-button type="primary" @click="edit">添加分类</el-button>
    </template>

    <el-table v-loading="isLoading" :data="channelList" style="width: 100%">
      <el-table-column type="index" label="序号" width="150" min-width="50" />
      <el-table-column prop="name" label="分类名称" />
      <el-table-column prop="alias" label="分类别名" />
      <el-table-column label="操作" width="150" min-width="50">
        <template #default="{ row, $index }">
          <el-button type="primary" plain @click="edit(row, $index)" :icon="Edit" circle />
          <el-button type="danger" @click="del(row, $index)" plain :icon="Delete" circle />
        </template>
      </el-table-column>
      <template #empty>
        <el-empty description="没有数据"></el-empty>
      </template>
    </el-table>
    <ChannelEdit ref="channelEdit" @success="getChannelList"></ChannelEdit>
  </page-container>
</template>
